package Platform.WandaTodo;

import Base.DataFactory;
import Base.TestBase;
import org.apache.commons.lang.StringUtils;
import org.testng.Assert;

/**
 * Created by Alain on 2016/3/9.
 */
public class Todo extends TestBase {
    private static TestBase TB = new TestBase();
    private static DataFactory DF = new DataFactory();
    private String requestURL=null, response=null,
                todoId          =   DF.getCellValue("WandaTodo", "todoId"),
                pageIndex       =   DF.getCellValue("WandaTodo", "pageIndex"),
                pageItemCount   =   DF.getCellValue("WandaTodo", "pageItemCount"),
                status          =   DF.getCellValue("WandaTodo", "status");

    /*获取待办列表
    GET  https://bim.wanda.cn/platform/todo?status={status}&pageIndex={pageIndex}&pageItemCount={pageItemCount}
    参数名          是否必选        类型     描述
    status  	      否	        byte	 1.待办；2.已办，不带参数默认为待办
    pageIndex	      否	        string	 当前页
    pageItemCount     否	        string	 每页显示数量，默认或最大为100条。*/
    public String getTodoList(){
        //initial parameters
        requestURL="/platform/todo?";

        if (StringUtils.isNotBlank(status)){
            requestURL = TB.getURL(requestURL) + "status=" + status;
        }
        if (StringUtils.isNotBlank(pageIndex)){
            requestURL = TB.getURL(requestURL) + "pageIndex=" + pageIndex;
        }
        if (StringUtils.isNotBlank(pageItemCount)){
            requestURL = TB.getURL(requestURL) + "pageItemCount=" + pageItemCount;
        }

        //send request
        try {
            response = TB.apiResponse(requestURL, "GET");
        } catch (Exception e){
            Assert.fail("");
        }
        return response;
    }

    /*更改待办为已读
    PUT  https://bim.wanda.cn/platform/todo/{todoId}/read
    参数名          是否必选        类型     描述
    todoId  	      是	        String	 待办Id*/
    public String changeTodoStatus(){
        requestURL = "/platform/todo/"+todoId+"/read";

        //send request
        try {
            TB.apiResponse(requestURL, "PUT");
        } catch (Exception e){
            Assert.fail("");
        }
        return response;
    }
}
